local jianman = fk.CreateSkill{
  name = "mod__jianman",
  anim_type = "special",
}
local jianman_ = {
  can_trigger = function(self, event, target, player, data)
    if not player.dead and player:hasSkill(self) and data.card then
      if data.card.type == Card.TypeBasic then
        local room = player.room
        local turn_event = room.logic:getCurrentEvent():findParent(GameEvent.Turn, true)
        local list = {}
        room.logic:getEventsByRule(GameEvent.UseCard, 1, function(e)
          if #list >= 3 then return true end
          local use = e.data
          if use.card.type == Card.TypeBasic then
            table.insert(list, {use.from, use.card})
          end
          return false
        end, turn_event.id)
        if #list ~= 2 then return false end
        self.cost_data = list
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local user1 = room:getPlayerById(self.cost_data[1][1])
    local user2 = room:getPlayerById(self.cost_data[2][1])
    if user1 == player and user2 == player then
      room:setPlayerMark(player, "jianman_delay-phase", 1)
    elseif user1 == player or user2 == player then
      local id
      if user1 == player and user2 then
        id = user2.id
      elseif user2 == player and user1 then
        id = user1.id
      end
      if id then
        local cid = room:askForCardChosen(player, room:getPlayerById(id), "he", self.name, "#jianman_gain_choose")
        room:obtainCard(player, cid, false, fk.ReasonPrey)
      end
    else
      local card = room:askForDiscard(player, 1, 1, true, self.name, true, nil, "#jianman_ask:::"..data.card:toLogString()) or {}
      if #card > 0 then
        player.room:obtainCard(player, data.card, true, fk.ReasonJustMove)
      end
    end
  end,
  refresh_events = {fk.EventPhaseEnd},
  can_refresh = function(self, event, target, player, data)
    return not player.dead and player:getMark("jianman_delay-phase") > 0
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local targets = table.map(room:getOtherPlayers(player), Util.IdMapper)
    local to = room:askForChoosePlayers(player, targets, 1, 1, "#jianman_damage_choose", self.name, true) or {}
    if #to > 0 then
      room:damage {
        from = player,
        to = room:getPlayerById(to[1]),
        damage = 1,
        skillName = self.name,
      }
    end
  end,
}
jianman:addEffect(fk.CardUsing, jianman_)
return jianman